/usr/local:
  archive.extracted:
    - source: salt://modules/prometheus/files/prometheus-2.31.1.linux-amd64.tar.gz
    - if_missing: /usr/local/prometheus-2.31.1.linux-amd64

{{ pillar['prometheus_dir'] }}:
  file.symlink:
    - target: /usr/local/prometheus-2.31.1.linux-amd64
    - unless: test -d {{ pillar['prometheus_dir'] }}

/usr/lib/systemd/system/prometheus.service:
  file.managed:
    - source: salt://modules/prometheus/files/prometheus.service.j2
    - template: jinja
    - require:
      - file: {{ pillar['prometheus_dir'] }}
  cmd.run:
    - name: systemctl daemon-reload

{{ pillar['prometheus_dir'] }}/prometheus.yml:
  file.managed:
    - source: salt://modules/prometheus/files/prometheus.yml.j2
    - template: jinja

prometheus.service:
  service.running:
    - enable: true
    - reload: true
    - watch:
      - cmd: /usr/lib/systemd/system/prometheus.service
      - file: {{ pillar['prometheus_dir'] }}/prometheus.yml
